package com.hs.communication.mqtt.service;

import com.hs.communication.common.entity.dto.ParaDto;
import com.hs.communication.common.message.MessageEntity;
import com.hs.communication.common.producer.IProducer;
import com.hs.communication.common.utils.ByteUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MqttService {

    @Resource
    private IProducer producer;

    public Boolean setParameter(ParaDto paraDto) {
        int funcCode = paraDto.getFuncCode();
        String sn = paraDto.getSn();
        int value = paraDto.getValue();

        MessageEntity entity = MessageEntity.builder().functionCode((byte) funcCode).frameNumber(ByteUtil.intToBytes(0)).data(new byte[]{(byte) value}).build();
        byte[] bytes = MessageEntity.getBytes(entity);
        return producer.send(sn, bytes);
    }
}
